package leetcode.datastructure.graph;

/**
 * 此方法解决方法不全
 */
public class Program200NumIslands {

    // 遍历上、左 结果便利不全，进一步 上右、下左、下右
    public int numIslands(char[][] grid) {
        int row = grid.length;
        int col = grid[0].length;
        int res = grid[0][0] == '1' ? 1 : 0;
        for (int i = 1; i < col; i++) {
            if (grid[0][i] == '1' && grid[0][i - 1] != '1') {
                res++;
            }
        }
        for (int i = 1; i < row; i++) {
            if (grid[i][0] == '1' && grid[i - 1][0] != '1') {
                res++;
            }
        }
        for (int i = 1; i < row; i++) {
            for (int j = 1; j < col; j++) {
                if (grid[i][j] == '1' && grid[i - 1][j] != '1' && grid[i][j - 1] != '1') {
                    res++;
                }
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Program200NumIslands myStack = new Program200NumIslands();
//        char[][] board = {
//                {'1','1','1','1','0'}
//                ,{'1','1','0','1','0'}
//                ,{'1','1','0','0','0'}
//                ,{'0','0','0','0','0'}
//        };
//        System.out.println(myStack.numIslands(board)); // 返回
//        char[][] board2 = {
//                {'1','1','0','0','0'}
//                ,{'1','1','0','0','0'}
//                ,{'0','0','1','0','0'}
//                ,{'0','0','0','1','1'}
//        };
//        System.out.println(myStack.numIslands(board2)); // 返回
        char[][] board3 = {
                {'1','1','1'}
                ,{'0','1','0'}
                ,{'1','1','1'}
        };
        System.out.println(myStack.numIslands(board3)); // 返回
    }
}
